package com.kerwin.sysmgt.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.util.Objects;

/*用户表*/
/*先手动生成，之后再自动*/
/*表名和类名与字段名对应*/
/*SysUser  sys_user*/
/*当不对应时 使用 @TableName("sys_user")*/
public class User implements Serializable {


    private static final long serialVersionUID = -2589200416098971116L;
    /*如果我的主键不叫id 叫uid之类的需要我指定告诉mp 那个属性是我的主键*/
    /*他需要根据这个主键去查询*/
    /* @TableId("数据库字段名 和 属性名不一致可以在这里指定，但是我没听懂写的是属性名，还是数据库的字段名")*/
    /* @TableId(value="数据库字段名",type=IdType.ASSIGN_ID)*/
    /*可以指定id生成策略，这里用的是雪花id，也可以用INPUT自己维护*/
    @TableId
    private String id          ;  //用户id
    /*用在非主键属性上*/
    /*@TableField("列名")*/
    /*1、属性名和列名不一致*/
    @TableField(whereStrategy = FieldStrategy.NOT_EMPTY,condition=SqlCondition.LIKE)
    private String userName   ;  //用户姓名
    private String userPassword ;//用户密码
    @TableField(whereStrategy = FieldStrategy.NOT_EMPTY)
    private String userPhone;
    private String userDepart ;  // 用户归属部门
    private Integer userGender ;  //用户性别 0是女 1是男
    private Integer userState  ;  //用户状态 0无效 1有效
    private String userRole   ;  //用户角色
    /*乐观锁，执行修改前执行查询  数据库类型为int*/
    /*两个人一起点修改，修改前已经拿到版本号，当version=0 与 数据库已经被第一个人修改后的 version=1 值不符 修改失败 前端刷新页面，重新加载数据*/
    /*version 注解想要生效需要添加插件*/

//    支持的数据类型只有:int,Integer,long,Long,Date,Timestamp,LocalDateTime
//    整数类型下 newVersion = oldVersion + 1
//    newVersion 会回写到 entity 中
//    仅支持 updateById(id) 与 update(entity, wrapper) 方法
//    在 update(entity, wrapper) 方法下, wrapper 不能复用!!!
    @Version
    private Integer version     ;  //乐观锁，更新前，执行查询
    @TableLogic
    /*还要在配置文件里面配置*/
    private Integer deleted     ;  //逻辑删除 0是未删除 1是已删除


    /*2、辅助性的字段,这个属性在数据库里不存在对应的列*/
    /*记住辅助字段一定要加注解，mp拼接属性名去写sql查询的*/
    /*@TableField(exist=false)*/

    /*3、用于wapper 查询*/
    /*@TableField(condition="%s=#{%s}")*/
    /*第一个是我的属性名  第二个是传入的动态变量*/
    /*其他用法把 字符串换成 SqlCondition. 里面去看*/

    /*4、前端条件查询默认为空，我想当他为null，为空的时候不查询*/
    /*whereStrategy = FieldStrategy.NOT_EMPTY*/


    /*只要是集合查询，前端显示列表的那个，一定要有排序字段*/
    /*https://www.mybatis-plus.com/guide/annotation.html#keysequence*/
    /*isDesc 是否倒序查询	   sort 数字越小越靠前	*/
    public User() {
    }

    public User(String id, String userName, String userPassword, String userPhone, String userDepart, Integer userGender, Integer userState, String userRole, Integer version, Integer deleted) {
        this.id = id;
        this.userName = userName;
        this.userPassword = userPassword;
        this.userPhone = userPhone;
        this.userDepart = userDepart;
        this.userGender = userGender;
        this.userState = userState;
        this.userRole = userRole;
        this.version = version;
        this.deleted = deleted;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserDepart() {
        return userDepart;
    }

    public void setUserDepart(String userDepart) {
        this.userDepart = userDepart;
    }

    public Integer getUserGender() {
        return userGender;
    }

    public void setUserGender(Integer userGender) {
        this.userGender = userGender;
    }

    public Integer getUserState() {
        return userState;
    }

    public void setUserState(Integer userState) {
        this.userState = userState;
    }

    public String getUserRole() {
        return userRole;
    }

    public void setUserRole(String userRole) {
        this.userRole = userRole;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Integer getDeleted() {
        return deleted;
    }

    public void setDeleted(Integer deleted) {
        this.deleted = deleted;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", userName='" + userName + '\'' +
                ", userPassword='" + userPassword + '\'' +
                ", userPhone='" + userPhone + '\'' +
                ", userDepart='" + userDepart + '\'' +
                ", userGender=" + userGender +
                ", userState=" + userState +
                ", userRole='" + userRole + '\'' +
                ", version=" + version +
                ", deleted=" + deleted +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(id, user.id) && Objects.equals(userName, user.userName) && Objects.equals(userPassword, user.userPassword) && Objects.equals(userPhone, user.userPhone) && Objects.equals(userDepart, user.userDepart) && Objects.equals(userGender, user.userGender) && Objects.equals(userState, user.userState) && Objects.equals(userRole, user.userRole) && Objects.equals(version, user.version) && Objects.equals(deleted, user.deleted);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, userName, userPassword, userPhone, userDepart, userGender, userState, userRole, version, deleted);
    }
}
